$(function(){
	
	document.documentElement.style.fontSize = window.innerWidth/3.75 + 'px';
	
	var tel,code;
	var shareKey=getQueryStr('shareKey');
	$('.getCode-btn').on('click',function(){
		
		
		var re = /^1[3|4|5|7|8][0-9]{9}$/;
        var tel_click = $("input[type='tel']").val();
        tel = tel_click;
        
        if(re.test(tel)){
        	//一分钟之后才能继续获取
        	var count = 60;
		    var countdown = setInterval(CountDown, 1000);
		    function CountDown() {
		        $(".getCode-btn").attr("disabled", true);
		        $(".getCode-btn").css({'background-color':'#939090'});
		        $(".getCode-btn").text(count + "s");
		        if (count == 0) {
		            $(".getCode-btn").text("获取验证码").removeAttr("disabled");
		            $(".getCode-btn").css({'background-color':'#FF4B4A'});
		            clearInterval(countdown);
		        }
		        count--;
		    }
		    //获取验证码
		    $.ajax({
				type: "post",
				url: "/dingding-web/moonActivityAction!getTelePhoneCode.action",
				dataType: "jsonp",
				async: false,
				jsonp: "callback",
				jsonpCallback: "success_jsop",
				data: {
					telephone: tel
				},
				success: function(data) {
					
				}
			});
		    
        }
        else {
        	alert('请输入正确的号码格式');
        }
		
	});
	//点击注册
	$('.register-btn').on('click',function(){
		tel = $('.tel-input').val();
		code = $('.code-input').val();
		if(tel && code) {
			$.ajax({
				type: "post",
				url: "/dingding-web/moonActivityAction!regMoonActivity.action",
				dataType: "jsonp",
				async: false,
				jsonp: "callback",
				jsonpCallback: "success_jsop",
				data: {
					telephone: tel,
					messageCode: code,
					shareKey: shareKey
				},
				success: function(data) {
					if(data.errorMessage == '验证码错误') {
						alert('请输入正确的验证码');
					}
					else {
						
						//新用户，跳转到注册成功，下载app页面
						if(data.responseBody.status == 1) {
							window.location.href = '/dingding-web/midAutumnActivity/successRegister.html?status='+data.responseBody.status;
						}
						//老用户没发起过活动，跳转到注册成功，下载app页面
						if(data.responseBody.status == 2) {
							window.location.href = '/dingding-web/midAutumnActivity/successRegister.html?status='+data.responseBody.status;
						}
						//老用户发起过活动,跳转到已邀请多少人数页面
						if(data.responseBody.status == 3) {
							window.location.href = '/dingding-web/midAutumnActivity/successInvite.html?nums='+data.responseBody.inviteNum+'&gift='+data.responseBody.gifts[0];
						}
					}
				}
			});
		}
		else {
			alert('请输入手机号码和验证码');
		}
	})
	
})